//
//  HotPostTableViewCell.m
//  初稿
//
//  Created by lanou3g on 15/7/18.
//  Copyright (c) 2015年 多飞科技. All rights reserved.
//

#import "HotPostTableViewCell.h"
#import "MyHandle.h"
#import "HotPost.h"
@implementation HotPostTableViewCell

- (void)awakeFromNib {
    
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

//-(UIImageView *)post_logoImageView{
//    
//    NSLog(@"--------------------getter");
//    return self.post_logoImageView;
//}

- (void)setPost_logoImageView:(UIImageView *)post_logoImageView{
    
    if (_post_logoImageView!=post_logoImageView) {
        _post_logoImageView=post_logoImageView;
    }

}

-(void)setHotPost:(HotPost *)hotPost{
    
    if (_hotPost!=hotPost) {
        _hotPost = hotPost;
        
    }
    
    
    if (self.post_logoImageView==nil) {
        self.post_logoImageView=[[UIImageView alloc]initWithFrame:CGRectMake(10, 120, 10, 120)];
//        self.post_logoImageView=[[UIImageView alloc]initWithFrame:CGRectMake(10, 20, 10, 120)];
        [self addSubview:self.post_logoImageView];
        
    }
    self.post_logoImageView.backgroundColor=[UIColor redColor];
    
    self.titleLabel.numberOfLines = 0;
    NSString * titleStr = [hotPost.title stringByReplacingOccurrencesOfString:@"&nbsp;" withString:@" "];
    self.titleLabel.text = titleStr;
    
    
    self.contentLabel.numberOfLines = 0;
    NSString * contentStr = [hotPost.contentSB stringByReplacingOccurrencesOfString:@"&nbsp;" withString:@" "];
    NSString * content = [contentStr stringByReplacingOccurrencesOfString:@"<br/>" withString:@"\n"];
    self.contentLabel.text = content;
    
    
    
    self.post_nameLabel.text = hotPost.post_name;
    self.post_timeLabel.text = hotPost.post_timeSB;
    self.comment_countLabel.text = hotPost.comment_countSB;
    self.praise_countLabel.text = hotPost.praise_countSB;
    self.post_avatarImageView.layer.cornerRadius = 20;
    self.post_avatarImageView.layer.masksToBounds = YES;

    
    
/********************************************/////
//    热门动态的图片大小设置
//    if ([hotPost.post_logo isEqualToString:@""]) {
////        self.post_logoImageView = nil;
//        self.post_logoImageView.frame=CGRectMake(self.post_logoImageView.frame.origin.x, self.post_logoImageView.frame.origin.y, 10, 0);
//        
//    }else {
////        self.post_logoImageView.hidden = NO;
//        CGFloat width1 = (120*self.post_logoImageView.image.size.width)/self.post_logoImageView.image.size.height;
//        self.post_logoImageView.frame = CGRectMake(self.post_logoImageView.frame.origin.x, self.post_logoImageView.frame.origin.y, width1, 120);
//    }
//    

    
    
    CGFloat titleLabelHeight = [MyHandle stringHeight:hotPost.title fontSize:14 width:self.titleLabel.frame.size.width];
    self.titleLabel.frame=CGRectMake(self.titleLabel.frame.origin.x, self.titleLabel.frame.origin.y, self.titleLabel.frame.size.width, titleLabelHeight);
    
    
    CGFloat contentLabelHeight = [MyHandle stringHeight:hotPost.contentSB fontSize:12 width:self.comment_countLabel.frame.size.width];
    self.contentLabel.frame = CGRectMake(self.contentLabel.frame.origin.x, CGRectGetMaxY(self.titleLabel.frame)+8, self.contentLabel.frame.size.width, contentLabelHeight);
    
//    self.post_logoImageView.frame=CGRectMake(10, CGRectGetMaxY(self.contentLabel.frame)+8, 10, 120);
    
#warning 代码创建post_ImageView
//    if (self.post_logoImageView==nil) {
//        self.post_logoImageView=[[UIImageView alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(self.contentLabel.frame)+8, 10, 120)];
//        [self addSubview:self.post_logoImageView];
//        
//    }
    
    
    CGFloat logoHeight=0;
    if (self.hotPost.post_logo) {
        logoHeight=120;
    }
    /*
    //定义block，在tVC中，请求好logo图片后进行回调，但这里会有一个block的嵌套；在tVC中需要有两个地方来保证回调一定能实现（因为图片可能会从本地或者网上获取），暂空
    
    //下面的方法写在block的定义当中
    //研究UIImage本身的宽高怎么获得
    //imageView的高度也会有变化，所以要共用cell的话，需要自定义init方法，并设置一个BOOL类型的参数来判断cell的用途
//    self.post_logoImageView.frame=CGRectMake(self.post_logoImageView.frame.origin.x, CGRectGetMaxY(self.contentLabel.frame)+8, <#CGFloat width#>, logoHeight);
  */  
    
}


- (IBAction)praiseButton:(id)sender {
    

    
    
    static int i = 0;
    if (i == 0) {
        
        NSString *praise = self.praise_countLabel.text;
        NSInteger a = [praise integerValue];
        a = a+1;
        CAKeyframeAnimation *k = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
        k.values = @[@(0.1),@(1.0),@(1.5)];
        k.keyTimes = @[@(0.0),@(0.5),@(0.8),@(1.0)];
        k.calculationMode = kCAAnimationLinear;
        [self.praiseCountButton.layer addAnimation:k forKey:@"SHOW"];
        NSString *praiseStr = [NSString stringWithFormat:@"%lu",a];
        self.praise_countLabel.text = praiseStr;
        i = 1;
        
    }else{
        
        NSString *praise = self.praise_countLabel.text;
        NSInteger a = [praise integerValue];
        a = a-1;
        CAKeyframeAnimation *k = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
        k.values = @[@(0.1),@(1.0),@(1.5)];
        k.keyTimes = @[@(0.0),@(0.5),@(0.8),@(1.0)];
        k.calculationMode = kCAAnimationLinear;
        [self.praiseCountButton.layer addAnimation:k forKey:@"SHOW"];
        NSString *praiseStr = [NSString stringWithFormat:@"%lu",a];
        self.praise_countLabel.text = praiseStr;
        i = 0;
        
    }
    
    
    
    
    
    
    
}






@end
